﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using ORM_Benchmark.Runner.Interface;

namespace ORM_Benchmark.Runner.EFv41
{
    public class EFv41ProductContext : DbContext
    {
        private readonly bool _useModelBuilderConfig;
        public EFv41ProductContext(IConnect connection, bool useModelBuilderConfig) : base(connection.ConnectionString)
        {
            _useModelBuilderConfig = useModelBuilderConfig;
        }

        public DbSet<Efv41Product> Products { get; set; }
        public DbSet<EfEntityTypeProduct> EntityProducts { get; set; }

        internal void Insert(List<Efv41Product> ef4Products)
        {
            ef4Products.ForEach(product => Products.Add(product));
            SaveChanges();
        }

        internal void Insert(List<EfEntityTypeProduct> efv41EntityTypeProducts)
        {
            efv41EntityTypeProducts.ForEach(product => EntityProducts.Add(product));
            SaveChanges();
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            if (_useModelBuilderConfig)
                modelBuilder.Configurations.Add(new EFv41ProductMapping());
            base.OnModelCreating(modelBuilder);
        }
    }
}
